package csu.jpetstore.jpetstore.service;

import csu.jpetstore.jpetstore.domain.AdminUserRole;
import csu.jpetstore.jpetstore.repository.AdminUserRoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.management.relation.Role;
import java.util.ArrayList;
import java.util.List;

@Service
public class AdminUserRoleService {
    @Autowired
    AdminUserRoleRepository adminUserRoleRepository;

    public List<Integer> getRoleIdByUserId(String userId){
        List<AdminUserRole> adminUserRoles = adminUserRoleRepository.findAllByUserId(userId);
        List<Integer> roles = new ArrayList<>();
        for (AdminUserRole adminUserRole : adminUserRoles) {
            roles.add(adminUserRole.getRoleId());
        }
        return roles;
    }


    public void createNormalUser(String userId){
        AdminUserRole newUser = new AdminUserRole();
        newUser.setUserId(userId);
        newUser.setRoleId(5);
        adminUserRoleRepository.save(newUser);
    }
}
